package club.vann.kafka.mock.controller;

import club.vann.kafka.mock.kafka.KafkaProducer;
import club.vann.kafka.mock.kafka.KafkaTopicFactory;
import club.vann.kafka.mock.service.*;
import club.vann.kafka.mock.service.perp.PerpetualService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/message")
@RequiredArgsConstructor
@RestController
@Slf4j
public class MessageController extends BaseController {
  private final CreditPriceStatusService creditPriceStatusService;
  private final KafkaProducer kafkaProducer;
  private final MarketPriceService marketPriceService;
  private final PerpetualService perpetualService;
  private final QuoteActionService quoteActionService;
  private final QuoteMarketDataService quoteMarketDataService;
  private final RealizedVolatilityService realizedVolatilityService;
  private final PriceDirectionService priceDirectionService;

  /** Zhouyi重启消息 */
  @GetMapping("/zhouyi/init")
  public void zhouyiInit() {
    log.info("Zhouyi系统重启");
    this.kafkaProducer.send(KafkaTopicFactory.ZHOUYI_INIT_OUTPUT, new byte[] {});
  }

  /** 模拟市场价格数据推送。 */
  @GetMapping("/market/price")
  public void marketPrice() {
    log.info("推送MarketPrice数据");
    this.marketPriceService.marketPrice();
  }

  /** 模拟报价操作结果推送。 */
  @GetMapping("/quote/action/result")
  public void quoteActionResult(
      @RequestParam String clientId,
      @RequestParam String id,
      @RequestParam String venue,
      @RequestParam String ticker) {
    log.info("模拟报价操作结果推送 ClientID：{} ID：{}", clientId, id);
    this.quoteActionService.actionResult(clientId, id, venue, ticker);
  }

  /** 模拟波动率数据推送。 */
  @GetMapping("/realized/volatility")
  public void realizedVolatility() {
    log.info("推送RealizedVolatility数据");
    this.realizedVolatilityService.publisher(null);
  }

  /** 模拟CreditPriceStatus数据推送。 */
  @GetMapping("/credit/price/status")
  public void creaditPriceStatus() {
    log.info("推送CreditPriceStatus数据");
    this.creditPriceStatusService.creditPriceStatus();
  }

  /** 模拟QuoteMarketData数据推送。 */
  @GetMapping("/quote/market/data")
  public void quoteMarketData() {
    log.info("推送QuoteMarketData数据");
    this.quoteMarketDataService.publish();
  }

  /** 模拟PariSummary数据推送。 */
  @GetMapping("/perp/pair/summary")
  public void perpetualPairSummaryInfo() {
    log.info("模拟PariSummary数据推送");
    this.perpetualService.pairSummary();
  }

  /** 模拟PriceDirection数据推送。 */
  @GetMapping("/price/direction")
  public void priceDirection() {
    log.info("模拟PriceDirection数据推送");
    this.priceDirectionService.send();
  }
}
